package com.ruoyi.production.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.production.domain.WorkReport;
import com.ruoyi.production.domain.WorkReportComponents;
import com.ruoyi.production.service.IWorkReportComponentsService;
import com.ruoyi.production.service.IWorkReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 生产绩效Controller
 *
 * @author ruoyi
 * @date 2022-09-05
 */
@RestController
@RequestMapping("/production/WorkReportComponents")
public class WorkReportComponentsController extends BaseController {
    @Autowired
    private IWorkReportComponentsService workReportComponentsService;

    @Autowired
    private IWorkReportService workReportService;


    /**
     * 查询生产绩效列表
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportComponents:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkReport workReport) {
        startPage();
        //零件查询0，构件查询1
        workReport.setReportType("0");
        List<WorkReport> list = workReportService.selectWorkReportList(workReport);
        return getDataTable(list);
    }

    /**
     * 导出生产绩效列表
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportComponents:export')")
    @Log(title = "生产绩效", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkReport workReport) {
        //零件查询0，构件查询1
        workReport.setReportType("0");
        List<WorkReport> list = workReportService.selectWorkReportList(workReport);
        ExcelUtil<WorkReport> util = new ExcelUtil<WorkReport>(WorkReport.class);
        util.exportExcel(response, list, "生产绩效数据");
    }

    /**
     * 获取生产绩效详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportComponents:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(workReportComponentsService.selectWorkReportComponentsById(id));
    }

    /**
     * 新增生产绩效
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportComponents:add')")
    @Log(title = "生产绩效", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkReportComponents workReportComponents) {
        return toAjax(workReportComponentsService.insertWorkReportComponents(workReportComponents));
    }

    /**
     * 修改生产绩效
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportComponents:edit')")
    @Log(title = "生产绩效", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkReportComponents workReportComponents) {
        return toAjax(workReportComponentsService.updateWorkReportComponents(workReportComponents));
    }

    /**
     * 删除生产绩效
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportComponents:remove')")
    @Log(title = "生产绩效", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(workReportComponentsService.deleteWorkReportComponentsByIds(ids));
    }
}
